package main.java.jvm;

import java.io.*;

public class MyClassLoader extends ClassLoader{
    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        File file = new File("D:/test/", name.replace(".", "/").concat(".class"));
        try {
            FileInputStream fis = new FileInputStream(file);
            ByteArrayOutputStream bts = new ByteArrayOutputStream();
            int b = 0;
            while((b=fis.read())!=-1){
                bts.write(b);
            }

            byte[] bytes = bts.toByteArray();

            bts.close();
            fis.close();
            return defineClass(name,bytes,0,bytes.length);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.findClass(name);
    }
}
